package com.lineage.server.model.weaponskill;

import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class W_SK0014 extends L1WeaponSkillType {
  private static final Log _log = LogFactory.getLog(W_SK0014.class);
  
  private static final Random _random = new Random();
  
  public static L1WeaponSkillType get() {
    return new W_SK0014();
  }
  
  public double start_weapon_skill(L1PcInstance pc, L1Character target, L1ItemInstance weapon, double srcdmg) {
    try {
      int chance = _random.nextInt(1000);
      if (random(weapon) + pc.getWeaponSkillChance() * 10 < chance)
        return 0.0D; 
      if (target.hasSkillEffect(31)) {
        target.removeSkillEffect(31);
        int castgfx2 = SkillsTable.get().getTemplate(31).getCastGfx2();
        target.broadcastPacketAll((ServerBasePacket)new S_SkillSound(target.getId(), castgfx2));
        if (target instanceof L1PcInstance) {
          L1PcInstance tgpc = (L1PcInstance)target;
          tgpc.sendPacketsAll((ServerBasePacket)new S_SkillSound(tgpc.getId(), castgfx2));
        } 
        return 0.0D;
      } 
      if (target.hasSkillEffect(153))
        target.removeSkillEffect(153); 
      double damage = DmgAcMr.getDamage(pc);
      double SPINT = DmgAcMr.getSpInt(pc);
      int dice = this._type1 + _random.nextInt(this._type2);
      int def = calc_resist(target);
      double outdmg = calc_mr(pc, target, (SPINT - 4.0D - def) * dice / 32.0D * bon(), weapon);
      if (this._type3 > 0)
        outdmg *= this._type3 / 100.0D; 
      if (pc.getWeaponSkillDmg() != 0.0D)
        outdmg += outdmg * pc.getWeaponSkillDmg(); 
      show(pc, target);
      return outdmg;
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
      return 0.0D;
    } 
  }
}
